import InputNumber from "ant-design-vue/es/input-number";
import "ant-design-vue/lib/input-number/style/css";

export default {
  name: "FormNumber",
  props: {
    option: {
      type: Object,
      default() {
        return {};
      }
    },
    value: [Number, String]
  },
  model: {
    prop: "value",
    event: "updata"
  },
  data() {
    return {
      isFocus: false
    };
  },

  methods: {
    onChange(value) {
      this.$emit("updata", value);
      this.$emit("change", value);
    },
    setFocus(is) {
      if (is) {
        this.$refs.formInput.focus();
      } else {
        this.$refs.formInput.blur();
      }
    }
  },
  render() {
    const that = this;
    const props = {
      ref: "formInput",
      props: {
        ...this.option.props
      },
      style: {
        width: this.option.width ? this.option.width : "100%"
      },
      on: {
        change: e => {
          that.onChange(e);
        },
        focus: e => {
          this.$emit("focus", e);
        },
        blur: e => {
          this.isFocus = false;
          this.$emit("blur", e);
        }
      }
    };

    if (this.value) {
      props.props.value = this.value;
    }

    return <InputNumber {...props} />;
  }
};
